package 算法.leetcode.labuladong.数组和链表;

/**
 * @author lchenglong
 * @date 2022/6/16
 */
public class 移动零 {
    class Solution {
        public void moveZeroes(int[] nums) {
            int index = removeElement(nums, 0);
            for (;index<nums.length;index++){
                nums[index] = 0;
            }
        }
        public int removeElement(int[] nums, int val) {
            if (nums.length == 0)   return 0;
            int fast = 0,slow=0;
            while (fast<nums.length){
                if (nums[fast] != val){
                    //  保证nums[0..slow-1] 是不包含值为 val 的元素的
                    slow++;
                    nums[slow] = nums[fast];
                }
                fast++;
            }
            return slow;
        }
    }
}
